package com.fishery.refrigeratory.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fishery.refrigeratory.entity.RefrigeratoryOutInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface RefrigeratoryOutInfoMapper extends BaseMapper<RefrigeratoryOutInfo> {
    //根据入库id删除其对应的所有出库信息表
    @Delete(value = "DELETE FROM fishery_cloud_refrigeratory.`t_refrigeratory_out_info` WHERE refrigeratory_in_id = #{id};")
    void deleteByRefrigeratoryInId(String id);

    //根据产品编号溯源接口
    @Select(value =
            "SELECT " +
            "A.base_id, A.refrigeratory_name, B.gmt_create, C.gmt_modified, B.warehousing_person_id, C.warehousing_person_id " +
            "FROM " +
            "t_refrigeratory_info AS A, " +
            "t_refrigeratory_in_info AS B, " +
            "t_refrigeratory_out_info AS C " +
            "WHERE " +
            "A.id = B.refrigeratory_id AND A.id = C.`refrigeratory_id` AND B.id = C.refrigeratory_in_id AND C.id = #{id};")
    String getProduct(String id);

    //查看已经出库容量的总和
    @Select(value = "SELECT SUM(refrigeratory_out_capacity) FROM fishery_cloud_refrigeratory.`t_refrigeratory_out_info` WHERE refrigeratory_in_id = #{id};")
    Double selectByReInId(String id);
}
